home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
WINPROGS
/
WTJ208.ZIP
/
MILLER
/
CGWINDOW.CPP
next >
Wrap
C/C++ Source or Header
|
1993-04-11
|
14KB
|
453 lines
//----------------------------------------------------------------------
// File: CGWINDOW.CPP
//----------------------------------------------------------------------
#pragma hdrstop
#include <owl.h>
#include <button.h>
#include <checkbox.h>
#include <groupbox.h>
#include <radiobut.h>
#include <static.h>
#include <combobox.h>
#include <edit.h>
#include <scrollba.h>
#include <btree.h>
#include <stdtempl.h>
#include "cgwindow.h"
//----------------------------------------------------------------------
// GLOBAL VARIABLES
//----------------------------------------------------------------------
Btree registerWindowTypes;
PTGroupBox activeGroup;
static char xxButton = BUTTONCLASS,
xxEdit = EDITCLASS,
xxStatic = STATICCLASS,
xxListBox = LISTBOXCLASS,
xxScrollBar = SCROLLBARCLASS,
xxComboBox = COMBOBOXCLASS;
//----------------------------------------------------------------------
// Registration of predefined controls
//----------------------------------------------------------------------
CGWindowRegister regButton(&xxButton, BuildButton);
CGWindowRegister regEdit(&xxEdit, BuildEdit);
CGWindowRegister regStatic(&xxStatic, BuildStatic);
CGWindowRegister regListBox(&xxListBox, BuildListBox);
CGWindowRegister regScrollBar(&xxScrollBar, BuildScrollBar);
CGWindowRegister regComboBox(&xxComboBox, BuildComboBox);
//----------------------------------------------------------------------
// Class: CGWindow
//----------------------------------------------------------------------
CGWindow::CGWindow(PTWindowsObject AParent, LPSTR ATitle)
: TWindow(AParent, ATitle) {
// Allow keyboard controls
EnableKBHandler();
// Initialize scrolling
Attr.Style |= WS_HSCROLL | WS_VSCROLL;
Scroller = new TScroller(this, 1, 1, 0, 0);
Scroller->XLine = Scroller->YLine = 20;
// Store resource name
if(ATitle)
AResourceName = strdup(ATitle);
hFont = 0;
} // F: CGWindow::CGWindow
//----------------------------------------------------------------------
// F: CGWindow::~CGWindow
//----------------------------------------------------------------------
CGWindow::~CGWindow() {
// Delete Font
if (hFont)
DeleteObject(hFont);
// Delete resource name
if (AResourceName)
delete AResourceName;
} // F: CGWindow::~CGWindow
//----------------------------------------------------------------------
// F: CGWindow::CreateFont
//----------------------------------------------------------------------
HFONT CGWindow::CreateFont(LPSTR lpszFaceName, int
nPointSize) {
LOGFONT lf;
HDC hDC;
memset(&lf, 0, sizeof(LOGFONT));
hDC = GetDC(NULL);
lf.lfHeight = -MulDiv(nPointSize, GetDeviceCaps(hDC,
LOGPIXELSY), 72);
ReleaseDC(NULL, hDC);
lf.lfWeight = FW_BOLD;
lf.lfQuality = PROOF_QUALITY;
lf.lfPitchAndFamily = FF_DONTCARE;
strcpy(lf.lfFaceName, lpszFaceName);
return CreateFontIndirect(&lf);
} // F: CGWindow::CreateFont
//----------------------------------------------------------------------
// F: CGWindow::PreProcessControl
//----------------------------------------------------------------------
void CGWindow::PreProcessControl(DLGITEM & ADlgItem) {
// Scale Coordinates
ADlgItem.X = MulDiv(ADlgItem.X, nScaleX, 4);
ADlgItem.Y = MulDiv(ADlgItem.Y, nScaleY, 8);
ADlgItem.CX = MulDiv(ADlgItem.CX, nScaleX, 4);
ADlgItem.CY = MulDiv(ADlgItem.CY, nScaleY, 8);
if((ADlgItem.Style & WS_GROUP) == WS_GROUP)
activeGroup = NULL;
} // F: CGWindow::PreProcessControl
//----------------------------------------------------------------------
// F: CGWindow::ProcessControl
//----------------------------------------------------------------------
PTWindowsObject CGWindow::ProcessControl(DLGITEM & DlgItem)
{
PTWindowsObject pAControl = NULL;
// Construct Child Window
PCGWindowRegister reg =
PCGWindowRegister(®isterWindowTypes.
findMember(CGWindowRegister(DlgItem.Class,
NULL)));
if(reg != ZERO)
pAControl = reg->Build(this, DlgItem);
return pAControl;
} // F: CGWIndow::ProcessControl
//----------------------------------------------------------------------
// F: CGWindow::PostProcessControl
//----------------------------------------------------------------------
void CGWindow::PostProcessControl(PTWindowsObject AControl,
DLGITEM & ADlgItem) {
// Assign resource's style bits
PTWindow(AControl)->Attr.Style = ADlgItem.Style;
} // F: CGWIndow::PostProcessControl
//----------------------------------------------------------------------
// F: CGWindow::SetupWindow
//----------------------------------------------------------------------
void CGWindow::SetupWindow() {
RECT rect;
POINT pt;
HANDLE hMem;
LPSTR lpDlg;
PDLGFONTHDR pFontHdr = new DLGFONTHDR;
PDLGITEM pDlgItem = new DLGITEM;
PDLGHDR pDlgHdr = new DLGHDR;
// Load & Lock Dialog Resource
hMem = LoadResource(GetModule()->hInstance,
FindResource(GetModule()->hInstance, AResourceName,
RT_DIALOG));
lpDlg = LockResource(hMem);
// Retrieve Dialog Header
lpDlg = GetDlgInfo((LPDLGTEMPLATE) lpDlg, pDlgHdr);
// Retrieve Dialog Font Information
if (pDlgHdr->Style & DS_SETFONT) {
lpDlg = GetFontInfo(lpDlg, pFontHdr);
hFont = CreateFont(pFontHdr->szTypeFace,
pFontHdr->PointSize);
}
// Scale Coordinates
TEXTMETRIC tm;
HDC hDC = GetDC(NULL);
HFONT hSaveFont = SelectObject(hDC, hFont);
GetTextMetrics(hDC, &tm);
SelectObject(hDC, hSaveFont);
ReleaseDC(NULL, hDC);
nScaleX = tm.tmAveCharWidth + tm.tmOverhang;
nScaleY = tm.tmHeight;
Place.left = MulDiv(pDlgHdr->X, nScaleX, 4);
Place.top = MulDiv(pDlgHdr->Y, nScaleY, 8);
Place.right = Attr.W = pDlgHdr->CX = MulDiv(pDlgHdr-
>CX, nScaleX, 4);
Place.bottom = Attr.H = pDlgHdr->CY = MulDiv(pDlgHdr-
>CY, nScaleY, 8);
// Retrieve Dialog Items & Construct Child Windows
for (int i = 0; i < pDlgHdr->ItemCount; i++) {
// Retrieve Dialog Item
lpDlg = GetDlgItem((LPDLGITEMTEMPLATE)lpDlg,
pDlgItem);
PreProcessControl(*pDlgItem);
PTWindowsObject pAControl =
ProcessControl(*pDlgItem);
if(pAControl)
PostProcessControl(pAControl, *pDlgItem);
} // for
// Unlock & Free Resource
UnlockResource(hMem);
FreeResource(hMem);
SetCaption(pDlgHdr->CaptionText);
TWindow::SetupWindow();
ForEach(SetControlFont, &hFont);
GetWindowRect(HWindow, &rect);
pt.x = rect.left;
pt.y = rect.top;
ScreenToClient(Parent->GetClient() ?
Parent->GetClient()->HWindow :
Parent->HWindow, &pt);
MoveWindow(HWindow, pt.x, pt.y,
Place.right + (GetSystemMetrics(SM_CXFRAME) * 2),
Place.bottom + (GetSystemMetrics(SM_CYFRAME) * 2)
+
GetSystemMetrics(SM_CYCAPTION), FALSE);
delete pFontHdr;
delete pDlgItem;
delete pDlgHdr;
} // F: CGWindow::SetupWindow
//----------------------------------------------------------------------
// F: CGWindow::WMSize
//----------------------------------------------------------------------
void CGWindow::WMSize(RTMessage Msg) {
TWindow::WMSize(Msg);
int nX = max(int(Scroller->YRange ?
Place.right - Msg.LP.Lo -
GetSystemMetrics(SM_CXVSCROLL) :
Place.right - Msg.LP.Lo), 0);
int nY = max(int(Scroller->XRange ?
Place.bottom - Msg.LP.Hi -
GetSystemMetrics(SM_CYHSCROLL) :
Place.bottom - Msg.LP.Hi), 0);
Scroller->SetRange(nX, nY);
} // F: CGWindow::WMSize
//----------------------------------------------------------------------
// Class: CGWindowRegister
//--------------------